

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.ico">
  <link rel="icon" href="/img/favicon.ico">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="什么是tomcat？Apache Tomcat 是由Apache 软件基金会 开发的开源web服务器和servlet容器。它实现了Java Servlet，JavaServer页面（JSP），Java的统一表达式语言，以及Sun Microsystems的Java的WebSocket规范，并提供了一个运行java代码的web服务器环境。
Install and Config JavaTomcat要">
  <meta name="author" content="kinzun">
  <meta name="keywords" content>
  <meta name="description" content="什么是tomcat？Apache Tomcat 是由Apache 软件基金会 开发的开源web服务器和servlet容器。它实现了Java Servlet，JavaServer页面（JSP），Java的统一表达式语言，以及Sun Microsystems的Java的WebSocket规范，并提供了一个运行java代码的web服务器环境。 Install and Config JavaTomcat要">
<meta name="keywords" content="tomcat">
<meta property="og:type" content="article">
<meta property="og:title" content="tomcat memcache sticky sessions">
<meta property="og:url" content="https://kinzun.github.io/2017/05/20/tomcat/index.html">
<meta property="og:site_name" content="kinzun">
<meta property="og:description" content="什么是tomcat？Apache Tomcat 是由Apache 软件基金会 开发的开源web服务器和servlet容器。它实现了Java Servlet，JavaServer页面（JSP），Java的统一表达式语言，以及Sun Microsystems的Java的WebSocket规范，并提供了一个运行java代码的web服务器环境。 Install and Config JavaTomcat要">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://kinzun.github.io/images/tomcat/tomcatconfigvar.jpg">
<meta property="og:updated_time" content="2019-07-05T13:49:06.766Z">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="tomcat memcache sticky sessions">
<meta name="twitter:description" content="什么是tomcat？Apache Tomcat 是由Apache 软件基金会 开发的开源web服务器和servlet容器。它实现了Java Servlet，JavaServer页面（JSP），Java的统一表达式语言，以及Sun Microsystems的Java的WebSocket规范，并提供了一个运行java代码的web服务器环境。 Install and Config JavaTomcat要">
<meta name="twitter:image" content="https://kinzun.github.io/images/tomcat/tomcatconfigvar.jpg">
  
  <title>tomcat memcache sticky sessions - kinzun</title>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css">


  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css">
  <link rel="stylesheet" href="/lib/hint/hint.min.css">

  
    
    
      
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css">
    
  

  
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">

<link rel="stylesheet" href="/css/main.css">

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"kinzun.github.io","root":"/","version":"1.8.12","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname"}},"search_path":"/local-search.xml"};
  </script>
  <script src="/js/utils.js"></script>
  <script src="/js/color-schema.js"></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>kinzun</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="tomcat memcache sticky sessions">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2017-05-20 17:07" pubdate>
        2017年5月20日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      3.6k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      11 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">tomcat memcache sticky sessions</h1>
            
            <div class="markdown-body">
              <h2 id="什么是tomcat？"><a href="#什么是tomcat？" class="headerlink" title="什么是tomcat？"></a>什么是tomcat？</h2><p>Apache Tomcat 是由<a href="http://www.apache.org/" target="_blank" rel="noopener">Apache</a> 软件基金会 开发的开源web服务器和servlet容器。它实现了Java Servlet，JavaServer页面（JSP），Java的统一表达式语言，以及Sun Microsystems的Java的WebSocket规范，并提供了一个运行java代码的web服务器环境。</p>
<h3 id="Install-and-Config-Java"><a href="#Install-and-Config-Java" class="headerlink" title="Install and Config Java"></a>Install and Config Java</h3><p>Tomcat要求安装在服务器端Java，Java web应用程序代码才可执行<br>利用 yum 安装执行下面命令。</p>
<ul>
<li><p><a href="http://openjdk.java.net/" target="_blank" rel="noopener">OpenJDK</a></p>
<figure class="highlight shell"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs shell"><span class="hljs-meta">#</span><span class="bash"> yum install java-1.8.0-openjdk-devel</span><br></code></pre></div></td></tr></table></figure>
<p>alternatives 在常用用于安装同类软件不同版本</p>
</li>
</ul>
<p>tomcat通过JAVA_HOME变量找jdk安装目录。</p>
<p>设置JAVA_HOME环境变量<br><a id="more"></a>  </p>
<figure class="highlight routeros"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><br><span class="hljs-comment"># vim /etc/profile.d/java.sh</span><br><br><span class="hljs-builtin-name">export</span> <span class="hljs-attribute">JAVA_HOME</span>=/usr<br><span class="hljs-builtin-name">export</span> <span class="hljs-attribute">PATH</span>=<span class="hljs-variable">$JAVA_HOME</span>/bin:$PATH<br><span class="hljs-comment"># chmod u+x java.sh</span><br></code></pre></div></td></tr></table></figure>
<ul>
<li><p><a href="http://www.oracle.com/technetwork/java/javase/overview/index.html" target="_blank" rel="noopener">Oracle JDK</a></p>
<figure class="highlight routeros"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-comment"># vim /etc/profile.d/java.sh</span><br><br>epport <span class="hljs-attribute">JAVA_HOME</span>=/usr/java/default<br><span class="hljs-builtin-name">export</span> <span class="hljs-attribute">PATH</span>=<span class="hljs-variable">$JAVA_HOME</span>/bin:$PATH<br><span class="hljs-comment"># chmod u+x java.sh</span><br></code></pre></div></td></tr></table></figure>
</li>
<li><p>相关阅读</p>
<ul>
<li><a href="http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140763.html" target="_blank" rel="noopener">To explain the difference between JDK and JRE</a></li>
<li><a href="http://stackoverflow.com/questions/11547458/what-is-the-difference-between-jvm-jdk-jre-openjdk" target="_blank" rel="noopener">What is the difference between JVM, JDK, JRE &amp; OpenJDK?</a></li>
</ul>
</li>
</ul>
<h3 id="Tomcat-install"><a href="#Tomcat-install" class="headerlink" title="Tomcat install"></a>Tomcat install</h3><p>我们前往<a href="http://tomcat.apache.org/" target="_blank" rel="noopener">tomcat官方站点下载</a></p>
<figure class="highlight shell"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-meta">#</span><span class="bash"></span><br><span class="hljs-meta">#</span><span class="bash"> tar xvf apache-tomcat-VERSION.tar.gz -C /usr/<span class="hljs-built_in">local</span>/ </span><br><span class="hljs-meta">#</span><span class="bash"> <span class="hljs-built_in">cd</span> /usr/<span class="hljs-built_in">local</span>/ </span><br><span class="hljs-meta">#</span><span class="bash"> ln -sv apache-tomcat-VERSION tomcat </span><br><span class="hljs-meta"><br>#</span><span class="bash"> 添加变量		</span><br><span class="hljs-meta">#</span><span class="bash"> vim /etc/profile.d/tomcat.sh </span><br>export CATALINA_BASE=/usr/local/tomcat <br>export PATH=$CATALINA_BASE/bin:$PATH<br><span class="hljs-meta"><br>#</span><span class="bash"> . /etc/profile.d/tomcat.sh</span><br></code></pre></div></td></tr></table></figure>
<h3 id="Add-tomcat-user-amp-group"><a href="#Add-tomcat-user-amp-group" class="headerlink" title="Add tomcat user &amp; group"></a>Add tomcat user &amp; group</h3><figure class="highlight shell"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-meta">#</span><span class="bash"> groupadd tomcat</span><br><span class="hljs-meta">#</span><span class="bash"> useradd -g tomcat -s /sbin/nologin -d /usr/<span class="hljs-built_in">local</span>/tomcat/ tomcat</span><br><span class="hljs-meta">#</span><span class="bash"> chown -Rf tomcat.tomcat /usr/<span class="hljs-built_in">local</span>/tomcat</span><br></code></pre></div></td></tr></table></figure>
<h3 id="Runing-Tomcat"><a href="#Runing-Tomcat" class="headerlink" title="Runing Tomcat"></a>Runing Tomcat</h3><figure class="highlight shell"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-meta"><br>#</span><span class="bash"> /usr/<span class="hljs-built_in">local</span>/tomcat/bin/catalina.sh  start  或  <span class="hljs-comment">#catalina.sh  start</span></span><br></code></pre></div></td></tr></table></figure>
<h3 id="Config"><a href="#Config" class="headerlink" title="Config"></a>Config</h3><ul>
<li><p>tomcat目录结构</p>
<ul>
<li>bin： 脚本启动时用到的类</li>
<li>lib： 类库</li>
<li>conf： 配置文件</li>
<li>logs： 日志文件</li>
<li>webapps： 应用默认程序部署目录</li>
<li>work： 工作目录</li>
<li>tmp： 临时文件目录</li>
</ul>
</li>
<li><p>配置文件</p>
<ul>
<li>server.xml: 主配置文件；</li>
<li>context.xml: 每个webapp可以有专有的配置文件，这些配置文件通常位于webapp应用程序目录下的WEB-INF,用于定义会话管理，JDBC等；conf/context.xml是为webapp提供默认配置；</li>
<li>web.xml：每个webapp“部署”之后才可以被访问；此文件用于所以webapp的默认配置文件；</li>
<li>tomcat-users.xml: 用户认证帐号密码配置文件;</li>
<li>catalina.policy: 当使用-security选项启动tomcat实例，会读取此配置文件来实现其安全运行策略；</li>
<li>catalina.properties: Java属性定义文件，用于设定类加载器路径，以及一些JVM相关性能调优参数；</li>
<li>logging.properties; 日志相关的配置信息；</li>
</ul>
</li>
</ul>
<h3 id="测速页"><a href="#测速页" class="headerlink" title="测速页"></a>测速页</h3><p> vim </p>
<p>创建目录<br><figure class="highlight shell"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-meta">#</span><span class="bash"> <span class="hljs-built_in">cd</span> tomcat/webapps</span><br><span class="hljs-meta"><br>#</span><span class="bash"> mkdir myapp/&#123;lib,class,WEB-INF,META-INF&#125; -pv</span><br></code></pre></div></td></tr></table></figure></p>
<p><code># vim myapp/index.jsp</code><br><figure class="highlight"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs java"><br>&lt;%@ page language="java" %&gt;<br>&lt;html&gt;<br>  &lt;head&gt;&lt;title&gt;TomcatA&lt;/title&gt;&lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;h1&gt;&lt;font color="red"&gt;TomcatA.magedu.com&lt;/font&gt;&lt;/h1&gt;<br>    &lt;table align="centre" border="1"&gt;<br>      &lt;tr&gt;<br>        &lt;td&gt;Session ID&lt;/td&gt;<br>    &lt;% session.setAttribute("magedu.com","magedu.com"); %&gt;<br>        &lt;td&gt;&lt;%= session.getId() %&gt;&lt;/td&gt;<br>      &lt;/tr&gt;<br>      &lt;tr&gt;<br>        &lt;td&gt;Created on&lt;/td&gt;<br>        &lt;td&gt;&lt;%= session.getCreationTime() %&gt;&lt;/td&gt;<br>     &lt;/tr&gt;<br>    &lt;/table&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;<br></code></pre></div></td></tr></table></figure></p>
<p>###<br>环境目录如下<br>/usr/share/tomcat/webapps</p>
<p><code># tree /data/wepapps/</code></p>
<figure class="highlight crystal"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined">/data/wepapps/<br>└── ROOT<br>    ├── <span class="hljs-class"><span class="hljs-keyword">class</span></span><br>    ├── index.jsp<br>    ├── <span class="hljs-class"><span class="hljs-keyword">lib</span></span><br>    ├── META-INF<br>    └── WEB-INF<br></code></pre></div></td></tr></table></figure>
<ul>
<li><a href="https://my.oschina.net/sunchp/blog/616526" target="_blank" rel="noopener">Docker搭建Tomcat</a></li>
</ul>
<h3 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h3><p><img src="/images/tomcat/tomcatconfigvar.jpg" srcset="/img/loading.gif" lazyload alt="tomcat"></p>
<h4 id="memcached-session-manager项目地址下载地址，"><a href="#memcached-session-manager项目地址下载地址，" class="headerlink" title="memcached-session-manager项目地址下载地址，"></a>memcached-session-manager项目地址下载地址，</h4><ul>
<li><a href="http://code.google.com/p/memcached-session-manager" target="_blank" rel="noopener">Google</a> </li>
<li><a href="https://github.com/magro/memcached-session-manager" target="_blank" rel="noopener">GitHub</a></li>
</ul>
<p>需准备用到的jar扩展</p>
<blockquote>
<p>注意：不同的tomcat版本（tomcat6，tomcat7，tomcat8）所需的包不一样，需要针对tomcat版本下载对应的包.</p>
</blockquote>
<p>这是采用的javolution的序列化方式所有需要的包:</p>
<ul>
<li><a href="http://repo1.maven.org/maven2/de/javakaffee/msm/memcached-session-manager/" target="_blank" rel="noopener">memcached-session-manager-${version}.jar</a></li>
<li><a href="http://repo1.maven.org/maven2/de/javakaffee/msm/" target="_blank" rel="noopener">memcached-session-manager-tc${6,7,8}-${version}.jar</a></li>
<li><a href="http://repo1.maven.org/maven2/net/spy/spymemcached/2.11.1/spymemcached-2.11.1.jar" target="_blank" rel="noopener">spymemcached-${version}.jar</a></li>
<li><a href="http://repo1.maven.org/maven2/de/javakaffee/msm/msm-javolution-serializer/" target="_blank" rel="noopener">msm-javolution-serializer-${version}.jar</a></li>
<li><a href="https://raw.githubusercontent.com/kinzun/Config-Script/master/tomcat/memchachetestjavo/javolution-5.4.3.1.jar" target="_blank" rel="noopener">javolution-${version}.jar</a></li>
</ul>
<p>移动所有jar包到<br>mv *.jar /usr/share/tomcat/lib</p>
<p>配置memcache</p>
<p>###　Example for sticky sessions + javolution</p>
<p><code># vim $TOMCAT_HOME/conf/server.xml</code></p>
<figure class="highlight"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs java"><br>&lt;!-- &lt;Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true"&gt; <br>   此处下添加如--&gt;<br> &lt;Context path="" docBase="/usr/share/tomcat/webapps/test/" reloadable="true"&gt;<br>  &lt;Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:192.168.0.10:11211,n2:192.168.0.12:11211" <br>  failoverNodes="n1"<br>  requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"<br>  transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"<br>              /&gt;<br>             &lt;/Context&gt;<br></code></pre></div></td></tr></table></figure>
<p>另一节点如此。</p>
<h3 id="Config-nginx-load-balancing"><a href="#Config-nginx-load-balancing" class="headerlink" title="Config nginx load balancing"></a>Config nginx load balancing</h3><figure class="highlight nginx"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-comment">#安装nginx</span><br><span class="hljs-attribute">yum</span> install nginx<br><span class="hljs-comment">#配置负载均衡</span><br>upstream tomcat_server &#123;<br>    <span class="hljs-attribute">server</span> <span class="hljs-number">192.168.0.12</span>;<br>    <span class="hljs-attribute">server</span> <span class="hljs-number">192.168.0.10</span>;<br>&#125;<br><br><span class="hljs-section">server</span> &#123;<br>    <span class="hljs-attribute">listen</span>       <span class="hljs-number">80</span>;<br>    <span class="hljs-attribute">server_name</span> <span class="hljs-number">192.168.0.13</span>;<br><br><span class="hljs-attribute">location</span> / &#123;<br><br>    <span class="hljs-attribute">proxy_pass</span> http://tomcat_server;<br>        <span class="hljs-attribute">proxy_set_header</span>  X-Real-IP  <span class="hljs-variable">$remote_addr</span>;  <br><br>&#125;<br></code></pre></div></td></tr></table></figure>
            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/tomcat/">tomcat</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2017/05/27/ansibleo/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">ansible总结</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2017/05/18/zabbixInstalldeploy/">
                        <span class="hidden-mobile">zabbix安装部署</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                

              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
